/**
 * @author maulin
 */
dojo.provide("medryx.widgets.Headshot");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("medryx.config");

dojo.declare("medryx.widgets.Headshot", [dijit._Widget, dijit._Templated], {
	templatePath:dojo.moduleUrl("medryx","widgets/_Headshot/Headshot.html"),
	provider:null,
	style:{},
	clickable:true,
	
	onProviderClicked:function(provider, e) {
		
	},
	
    _click:function(e) {
		this.onProviderClicked(this.provider, e);
	},
	
	onMouseOver:function() {
		if (this.clickable) {
			this.onMouseOver = function() {
				dojo.addClass(this.containerNode, "hover");
			}
		} else {
			this.onMouseOver = function() {
				//noop
			}
		}
		this.onMouseOver();
	   
	},
	onMouseOut:function() {
        if (this.clickable) {
            this.onMouseOut = function() {
                dojo.removeClass(this.containerNode, "hover");
            }
        } else {
            this.onMouseOut = function() {
                //noop
            }
        }
        this.onMouseOut();
	},
	
	postCreate:function() {
		if (this.provider === null) {
			throw new Error("must specify person");
		}
		dojo.style(this.domNode, this.style);
		
		var image = new Image();
		image.src=medryx.config.photoDirectory + "/" + this.provider.image;
		this.imageNode.appendChild(image);
		
		this.nameNode.innerHTML = this.provider.getFullName();
		this.specialtyNode.innerHTML = dojo.filter(this.provider.getSpecialties(), 
		      function(specialty) {return specialty && specialty.length} ).join("<br />");
			  
	   if (this.clickable) {
	       dojo.addClass(this.containerNode, "clickable")
	   }
	}
	
});
